#include "model/point.h"
#include <cmath>

Point::Point(coord x, coord y, coord z): x(x), y(y), z(z) {}

Point Point::vetorial(const Point &v) const {
    return Point(
                y * v.z - z * v.y,
                z * v.x - x * v.z,
                x * v.y - y * v.x);
}

Point Point::operator-(const Point &p) const {
    return Point(x-p.x, y-p.y, z-p.z);
}

bool Point::operator==(const Point &p) const {
    return x == p.x && y == p.y && z == p.z;
}

void Point::apply(const MatrixTransformation &m) {
    coord vx = x;
    coord vy = y;
    coord vz = z;

    x = m[0][0]*vx + m[0][1]*vy + m[0][2]*vz + m[0][3];
    y = m[1][0]*vx + m[1][1]*vy + m[1][2]*vz + m[1][3];
    z = m[2][0]*vx + m[2][1]*vy + m[2][2]*vz + m[2][3];
}

Point Point::operator+(const Point &p) const {
    return Point(x+p.x, y+p.y, z+p.z);
}

Point Point::operator*(const coord number) const {
    return Point(x*number, y*number, z*number);
}

Point Point::operator/(double number) const {
    return Point(x/number, y/number, z/number);
}

coord Point::operator *(const Point &p) const {
    return x*p.x + y*p.y + z*p.z;
}

Point Point::unit() const {
    coord length = (coord) sqrt( x*x + y*y + z*z );
    return Point(x/length, y/length, z/length);
}

coord Point::distance() const {
    return (coord) sqrt( x*x + y*y + z*z );
}

Point Point::min() {
    return Point(coord_min, coord_min, coord_min);
}

Point Point::max() {
    return Point(coord_max, coord_max, coord_max);
}

